cd "H:\Zheng_10223\Joint"
adopath + "H:\Zheng_10223\stata\binscatter\"
adopath + "H:\Zheng_10223\stata\estout\"

********** READ IN ENCLAVES ******* 

*******************
insheet using "cohort_2025.csv", clear


rename v75 mainparentinc_pct45_49

* gender 
gen girl=0
replace girl=1 if gender_child==2


* world area birth
encode world_area_birth, gen(sourceregion)

* schooling bins
encode schoolingbins_max, gen(schoolcat)

* cma
encode destination_cma, gen(cmacat)

* skill level

encode skill_level_cd11_main, gen(skillcat)

* language
gen language=0
replace language=1 if anyenglish_main=="TRUE" | anyfrench_main=="TRUE"

*********************** 
destring mainparentinc_pct45_49, replace force

destring birthyear_child, replace force

* categorical landing year
gen landingage_cat=""
replace landingage_cat="0-5" if landing_age<5
replace landingage_cat="5-9" if landing_age>=5 & landing_age<10
replace landingage_cat="10-14" if landing_age>=10 & landing_age<15
replace landingage_cat=">14" if landing_age>=15 

encode landingage_cat, gen(landingage_numer)

* landing age main parent
gen landingagemainind=0
replace landingagemainind=1 if landingagemain<40


gen refugee=0

* only: economic/refugee/business here
*replace business=1 if immigrationcategory=="Business"
replace refugee=1 if immigrationcategory=="Refugee" 

gen interactionrefugee=refugee*mainparentinc_pct45_49


**************** Intergenerational gap relative to economic
**************** refugee 


* 1. No Controls 
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee, robust

lincom  refugee + interactionrefugee*25

* 2. World Area Country : this imposes common support 


reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.sourceregion,  robust


lincom  refugee + interactionrefugee*25

* 3. Schooling Bins 
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.schoolcat, robust

lincom  refugee + interactionrefugee*25

* 4. Destination CMA 
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.cmacat if cmadrop==0, robust

lincom  refugee + interactionrefugee*25

* 5. Skill category 
* for skill: drop - not stated, retired, students
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.skillcat if skillcat!=9 & skillcat!=10 & skillcat!=2, robust

lincom  refugee + interactionrefugee*25

* 6. Language 
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee  i.language, robust

lincom  refugee + interactionrefugee*25
gen p25_6=`r(estimate)'
gen ub25_6=`r(estimate) + 1.96*r(se)'
gen lb25_6=`r(estimate) - 1.96*r(se)'



* land age main parent
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee  i.landingagemainind, robust

lincom  refugee + interactionrefugee*25


* landing age child 
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee  i.landingage_numer, robust

lincom  refugee + interactionrefugee*25

*8. enclaves 

reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.enclave, robust 

lincom  refugee + interactionrefugee*25
gen p25_8=`r(estimate)'
gen ub25_8=`r(estimate) + 1.96*r(se)'
gen lb25_8=`r(estimate) - 1.96*r(se)'

* married
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.married, robust 

lincom  refugee + interactionrefugee*25

* 9. All pre-landing controls 


reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.sourceregion i.schoolcat  i.skillcat i.language i.landingagemainind  i.married if skillcat!=9 & skillcat!=10 & skillcat!=2, robust

lincom  refugee + interactionrefugee*25

* 9. All controls 

reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.sourceregion i.schoolcat i.cmacat i.skillcat i.language i.landingagemainind i.landingage_numer i.enclave i.married if cmadrop!=0 &skillcat!=9 & skillcat!=10 & skillcat!=2, robust

lincom  refugee + interactionrefugee*25


********************************************************
**************** Intergenerational gap relative to economic
**************** refugee 


* 1. No Controls 
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee, robust

lincom  refugee + interactionrefugee*50



* 2. World Area Country : this imposes common support 


reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.sourceregion,  robust


lincom  refugee + interactionrefugee*50



* 3. Schooling Bins 
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.schoolcat, robust

lincom  refugee + interactionrefugee*50

* 4. Destination CMA 
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.cmacat if cmadrop==0, robust

lincom  refugee + interactionrefugee*50


* 5. Skill category 
* for skill: drop - not stated, retired, students
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.skillcat if skillcat!=9 & skillcat!=10 & skillcat!=2, robust

lincom  refugee + interactionrefugee*50

* 6. Language 
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee  i.language, robust

lincom  refugee + interactionrefugee*50
gen p25_6=`r(estimate)'
gen ub25_6=`r(estimate) + 1.96*r(se)'
gen lb25_6=`r(estimate) - 1.96*r(se)'

*7. Landing Age 
* landing age child 
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee  i.landingage_numer, robust

lincom  refugee + interactionrefugee*50

* land age main parent
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee  i.landingagemainind, robust

lincom  refugee + interactionrefugee*50

*8. enclaves 

reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.enclave, robust 

lincom  refugee + interactionrefugee*50
gen p25_8=`r(estimate)'
gen ub25_8=`r(estimate) + 1.96*r(se)'
gen lb25_8=`r(estimate) - 1.96*r(se)'

* married
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.married, robust 

lincom  refugee + interactionrefugee*50

* 9. All pre-landing controls 


reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.sourceregion i.schoolcat  i.skillcat i.language i.landingagemainind  i.married if skillcat!=9 & skillcat!=10 & skillcat!=2, robust

lincom  refugee + interactionrefugee*50

* 9. All controls 

reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.sourceregion i.schoolcat i.cmacat i.skillcat i.language i.landingagemainind i.landingage_numer i.enclave i.married if cmadrop!=0 &skillcat!=9 & skillcat!=10 & skillcat!=2, robust

lincom  refugee + interactionrefugee*50


**************** Intergenerational gap relative to economic
**************** refugee 

*75 
* 1. No Controls 
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee, robust

lincom  refugee + interactionrefugee*75


* 2. World Area Country : this imposes common support 


reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.sourceregion,  robust


lincom  refugee + interactionrefugee*75

* 3. Schooling Bins 
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.schoolcat, robust

lincom  refugee + interactionrefugee*75

* 4. Destination CMA 
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.cmacat if cmadrop==0, robust

lincom  refugee + interactionrefugee*75


* 5. Skill category 
* for skill: drop - not stated, retired, students
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.skillcat if skillcat!=9 & skillcat!=10 & skillcat!=2, robust

lincom  refugee + interactionrefugee*75

* 6. Language 
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee  i.language, robust

lincom  refugee + interactionrefugee*75
gen p25_6=`r(estimate)'
gen ub25_6=`r(estimate) + 1.96*r(se)'
gen lb25_6=`r(estimate) - 1.96*r(se)'

*7. Landing Age 
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee  i.landingage_numer, robust

lincom  refugee + interactionrefugee*75

* land age main parent
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee  i.landingagemainind, robust

lincom  refugee + interactionrefugee*75

*8. enclaves 

reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.enclave, robust 

lincom  refugee + interactionrefugee*75
gen p25_8=`r(estimate)'
gen ub25_8=`r(estimate) + 1.96*r(se)'
gen lb25_8=`r(estimate) - 1.96*r(se)'

* married
reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.married, robust 

lincom  refugee + interactionrefugee*75

* 9. All pre-landing controls 


reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.sourceregion i.schoolcat  i.skillcat i.language i.landingagemainind  i.married if skillcat!=9 & skillcat!=10 & skillcat!=2, robust

lincom  refugee + interactionrefugee*75

* 9. All controls 

reg child_income_ind_30_34_pct mainparentinc_pct45_49 interactionrefugee refugee i.sourceregion i.schoolcat i.cmacat i.skillcat i.language i.landingagemainind i.landingage_numer i.enclave i.married if cmadrop!=0 &skillcat!=9 & skillcat!=10 & skillcat!=2, robust

lincom  refugee + interactionrefugee*75
